package com.douqu.game.main.gui.component.impl;

import com.douqu.game.main.GameServer;
import com.douqu.game.main.gui.MainFrame;
import com.douqu.game.main.gui.component.i.Component;

import javax.swing.*;
import java.awt.*;



public class LabelComponent extends Component
{

	private Container container;
	
	public void setJFrame(JFrame frame)
	{
		this.frame = frame;
		container = frame.getContentPane();
	}

	
	public JLabel lPlayerCount; //玩家数量
	
	public JLabel lServerStartTime;
	
	public JLabel lServerTime;
	
	public JLabel lServerName;
	
	public JLabel [] lJobs;
	/** 从系统那挖过来的总内存 */
	public JLabel lTotalMem;
	/** 从系统那可以挖的最大内存 */
	public JLabel lMaxMem;
	/** 挖过来的内存中空闲部分 */
	public JLabel lFreeMem;
	
	public LabelComponent()
	{
		lServerStartTime = new JLabel();
		lServerStartTime.setForeground(Color.WHITE);
		lServerStartTime.setBounds(20,MainFrame.HEIGHT-65, 300, 50);
		
		lServerTime = new JLabel("");
		lServerTime.setForeground(Color.WHITE);
		lServerTime.setBounds(MainFrame.WIDTH-160,MainFrame.HEIGHT-65, 300, 50);
		
		lPlayerCount = new JLabel();
		lPlayerCount.setForeground(Color.WHITE);
		lPlayerCount.setBounds(MainFrame.WIDTH-170,60, 200, 50);

		lTotalMem = new JLabel();
		lTotalMem.setForeground(Color.WHITE);
		lTotalMem.setBounds(MainFrame.WIDTH-170,270,300,50);

		lMaxMem = new JLabel();
		lMaxMem.setForeground(Color.WHITE);
		lMaxMem.setBounds(MainFrame.WIDTH-170,300,300,50);

		lFreeMem = new JLabel();
		lFreeMem.setForeground(Color.WHITE);
		lFreeMem.setBounds(MainFrame.WIDTH-170,330,300,50);
		
//		lJobs = new JLabel[GameServer.JOB_COUNT];
//
//		for(int i = 0 ; i < GameServer.JOB_COUNT ; i ++)
//		{
//			lJobs[i] = new JLabel();
//			lJobs[i].setForeground(Color.WHITE);
//			lJobs[i].setBounds(MainFrame.WIDTH-145,50+(i*15), 200, 50);
//		}
		
		lServerName = new JLabel("Game Server");
		lServerName.setFont(new Font("TimesRoman",Font.BOLD,20));
		lServerName.setForeground(Color.WHITE);
		lServerName.setBounds(20, 0, MainFrame.WIDTH-40, 50);
	}
	
	
	public void addToFrame()
	{
		container.add(lServerStartTime);
		container.add(lServerTime);
		container.add(lPlayerCount);
		container.add(lTotalMem);
		container.add(lMaxMem);
		container.add(lFreeMem);
		container.add(lServerName);
		
		
//		for(int i = 0 ; i < GameServer.JOB_COUNT ; i ++)
//		{
//			container.add(lJobs[i]);
//		}
	}


	public void updatePlayerCount()
	{
		StringBuffer buffer = new StringBuffer();
		buffer.append("Connection:   ");
		buffer.append(GameServer.getInstance().getWorldManager().getPlayerCount());
		buffer.append(" / ");
		buffer.append(GameServer.getInstance().getWorldManager().getConnectionCount());

		lPlayerCount.setText(buffer.toString());
	}


	

}
